/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  @endpointMap = {
    cn-hangzhou = 'mt.cn-hangzhou.aliyuncs.com',
    ap-northeast-1 = 'mt.aliyuncs.com',
    ap-northeast-2-pop = 'mt.aliyuncs.com',
    ap-south-1 = 'mt.aliyuncs.com',
    ap-southeast-1 = 'mt.ap-southeast-1.aliyuncs.com',
    ap-southeast-2 = 'mt.aliyuncs.com',
    ap-southeast-3 = 'mt.aliyuncs.com',
    ap-southeast-5 = 'mt.aliyuncs.com',
    cn-beijing = 'mt.aliyuncs.com',
    cn-beijing-finance-1 = 'mt.aliyuncs.com',
    cn-beijing-finance-pop = 'mt.aliyuncs.com',
    cn-beijing-gov-1 = 'mt.aliyuncs.com',
    cn-beijing-nu16-b01 = 'mt.aliyuncs.com',
    cn-chengdu = 'mt.aliyuncs.com',
    cn-edge-1 = 'mt.aliyuncs.com',
    cn-fujian = 'mt.aliyuncs.com',
    cn-haidian-cm12-c01 = 'mt.aliyuncs.com',
    cn-hangzhou-bj-b01 = 'mt.aliyuncs.com',
    cn-hangzhou-finance = 'mt.aliyuncs.com',
    cn-hangzhou-internal-prod-1 = 'mt.aliyuncs.com',
    cn-hangzhou-internal-test-1 = 'mt.aliyuncs.com',
    cn-hangzhou-internal-test-2 = 'mt.aliyuncs.com',
    cn-hangzhou-internal-test-3 = 'mt.aliyuncs.com',
    cn-hangzhou-test-306 = 'mt.aliyuncs.com',
    cn-hongkong = 'mt.aliyuncs.com',
    cn-hongkong-finance-pop = 'mt.aliyuncs.com',
    cn-huhehaote = 'mt.aliyuncs.com',
    cn-north-2-gov-1 = 'mt.aliyuncs.com',
    cn-qingdao = 'mt.aliyuncs.com',
    cn-qingdao-nebula = 'mt.aliyuncs.com',
    cn-shanghai = 'mt.aliyuncs.com',
    cn-shanghai-et15-b01 = 'mt.aliyuncs.com',
    cn-shanghai-et2-b01 = 'mt.aliyuncs.com',
    cn-shanghai-finance-1 = 'mt.aliyuncs.com',
    cn-shanghai-inner = 'mt.aliyuncs.com',
    cn-shanghai-internal-test-1 = 'mt.aliyuncs.com',
    cn-shenzhen = 'mt.aliyuncs.com',
    cn-shenzhen-finance-1 = 'mt.aliyuncs.com',
    cn-shenzhen-inner = 'mt.aliyuncs.com',
    cn-shenzhen-st4-d01 = 'mt.aliyuncs.com',
    cn-shenzhen-su18-b01 = 'mt.aliyuncs.com',
    cn-wuhan = 'mt.aliyuncs.com',
    cn-yushanfang = 'mt.aliyuncs.com',
    cn-zhangbei-na61-b01 = 'mt.aliyuncs.com',
    cn-zhangjiakou = 'mt.aliyuncs.com',
    cn-zhangjiakou-na62-a01 = 'mt.aliyuncs.com',
    cn-zhengzhou-nebula-1 = 'mt.aliyuncs.com',
    eu-central-1 = 'mt.aliyuncs.com',
    eu-west-1 = 'mt.aliyuncs.com',
    eu-west-1-oxs = 'mt.aliyuncs.com',
    me-east-1 = 'mt.aliyuncs.com',
    rus-west-1-pop = 'mt.aliyuncs.com',
    us-east-1 = 'mt.aliyuncs.com',
    us-west-1 = 'mt.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('alimt', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model MachineTranslateECommerceRequest {
  contentFormat?: string(name='ContentFormat', description='This parameter is required.'),
  sourceLanguage?: string(name='SourceLanguage', description='This parameter is required.'),
  sourceText?: string(name='SourceText', description='This parameter is required.'),
  targetLanguage?: string(name='TargetLanguage', description='This parameter is required.'),
}

model MachineTranslateECommerceResponseBody = {
  requestId?: string(name='RequestId'),
  resultCode?: {
    code?: int32(name='Code'),
    message?: string(name='Message'),
  }(name='ResultCode'),
  success?: boolean(name='Success'),
  translateText?: string(name='TranslateText'),
}

model MachineTranslateECommerceResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: MachineTranslateECommerceResponseBody(name='body'),
}

/**
 * @param request MachineTranslateECommerceRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return MachineTranslateECommerceResponse
 */
async function machineTranslateECommerceWithOptions(request: MachineTranslateECommerceRequest, runtime: Util.RuntimeOptions): MachineTranslateECommerceResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.contentFormat)) {
    body['ContentFormat'] = request.contentFormat;
  }
  if (!Util.isUnset(request.sourceLanguage)) {
    body['SourceLanguage'] = request.sourceLanguage;
  }
  if (!Util.isUnset(request.sourceText)) {
    body['SourceText'] = request.sourceText;
  }
  if (!Util.isUnset(request.targetLanguage)) {
    body['TargetLanguage'] = request.targetLanguage;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'MachineTranslateECommerce',
    version = '2018-08-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request MachineTranslateECommerceRequest
 * @return MachineTranslateECommerceResponse
 */
async function machineTranslateECommerce(request: MachineTranslateECommerceRequest): MachineTranslateECommerceResponse {
  var runtime = new Util.RuntimeOptions{};
  return machineTranslateECommerceWithOptions(request, runtime);
}

model MachineTranslateGeneralRequest {
  contentFormat?: string(name='ContentFormat', description='This parameter is required.'),
  sourceLanguage?: string(name='SourceLanguage', description='This parameter is required.'),
  sourceText?: string(name='SourceText', description='This parameter is required.'),
  targetLanguage?: string(name='TargetLanguage', description='This parameter is required.'),
}

model MachineTranslateGeneralResponseBody = {
  requestId?: string(name='RequestId'),
  resultCode?: {
    code?: int32(name='Code'),
    message?: string(name='Message'),
  }(name='ResultCode'),
  success?: boolean(name='Success'),
  translateText?: string(name='TranslateText'),
}

model MachineTranslateGeneralResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: MachineTranslateGeneralResponseBody(name='body'),
}

/**
 * @param request MachineTranslateGeneralRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return MachineTranslateGeneralResponse
 */
async function machineTranslateGeneralWithOptions(request: MachineTranslateGeneralRequest, runtime: Util.RuntimeOptions): MachineTranslateGeneralResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.contentFormat)) {
    body['ContentFormat'] = request.contentFormat;
  }
  if (!Util.isUnset(request.sourceLanguage)) {
    body['SourceLanguage'] = request.sourceLanguage;
  }
  if (!Util.isUnset(request.sourceText)) {
    body['SourceText'] = request.sourceText;
  }
  if (!Util.isUnset(request.targetLanguage)) {
    body['TargetLanguage'] = request.targetLanguage;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'MachineTranslateGeneral',
    version = '2018-08-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request MachineTranslateGeneralRequest
 * @return MachineTranslateGeneralResponse
 */
async function machineTranslateGeneral(request: MachineTranslateGeneralRequest): MachineTranslateGeneralResponse {
  var runtime = new Util.RuntimeOptions{};
  return machineTranslateGeneralWithOptions(request, runtime);
}

